package codegen;

import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;

public class RecordDescr extends AbstractDescr {

    private static final long serialVersionUID = 1L;
    private Map<String, AbstractDescr> recsymbolTable;
    private int startAddr;

    public RecordDescr(int startAddr, Map<String, AbstractDescr> symbolTable) {
        super(computeSymbolSize(symbolTable));
        recsymbolTable = symbolTable;
        this.startAddr = startAddr;
    }

    public Map<String, AbstractDescr> getRecsymbolTable() {
        return recsymbolTable;
    }

    public void print() {
        trace("RecordDescr: size: " + size + "level: ");// + level);
        Iterator<AbstractDescr> it = recsymbolTable.values().iterator();
        while (it.hasNext()) {
            it.next().print();
        }
        unindent();
    }

    @Override
    public String toString() {
        return "Record[" + startAddr + ",\n" + recsymbolTable + "]" + super.toString();
    }
    
     
    private static int computeSymbolSize(Map<String, AbstractDescr> symbols) {
        int size = 0;
        for (AbstractDescr descr : symbols.values()) {
            size += descr.getSize();
        }
        return size;
    }
}